{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check If N and Its Double Exist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #two-pointers #binary-search #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #双指针 #二分查找 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: checkIfExist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #检查整数及其两倍数是否存在"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数数组&nbsp;<code>arr</code>，请你检查是否存在两个整数&nbsp;<code>N</code> 和 <code>M</code>，满足&nbsp;<code>N</code>&nbsp;是&nbsp;<code>M</code>&nbsp;的两倍（即，<code>N = 2 * M</code>）。</p>\n",
    "\n",
    "<p>更正式地，检查是否存在两个下标&nbsp;<code>i</code> 和 <code>j</code> 满足：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>i != j</code></li>\n",
    "\t<li><code>0 &lt;= i, j &lt; arr.length</code></li>\n",
    "\t<li><code>arr[i] == 2 * arr[j]</code></li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [10,2,5,3]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>N<code> = 10</code> 是 M<code> = 5 的两倍</code>，即 <code>10 = 2 * 5 。</code>\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [7,1,14,11]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>N<code> = 14</code> 是 M<code> = 7 的两倍</code>，即 <code>14 = 2 * 7 </code>。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [3,1,7,11]\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>在该情况下不存在 N 和 M 满足 N = 2 * M 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= arr.length &lt;= 500</code></li>\n",
    "\t<li><code>-10^3 &lt;= arr[i] &lt;= 10^3</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-n-and-its-double-exist](https://leetcode.cn/problems/check-if-n-and-its-double-exist/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-n-and-its-double-exist](https://leetcode.cn/problems/check-if-n-and-its-double-exist/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[10,2,5,3]', '[3,1,7,11]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        pre = set()\n",
    "        for num in arr:\n",
    "            if num % 2 == 0 and num //2 in pre:\n",
    "                return True\n",
    "            if num * 2 in pre:\n",
    "                return True\n",
    "            pre.add(num)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n - 1):\n",
    "            for j in range(i + 1, n):\n",
    "                if arr[i] == 2 * arr[j] or arr[i] * 2 == arr[j]:\n",
    "                    return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            if arr[i]*2>max(arr):\n",
    "                continue\n",
    "            for j in range(len(arr)):\n",
    "                if arr[i]*2==arr[j] and j!=i:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        if arr.count(0) >= 2:\n",
    "            return True\n",
    "        arr1 = [i*2 for i in arr]\n",
    "        for i in arr1:\n",
    "            if i in arr and i != 0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        counter = collections.Counter(arr)\n",
    "        for n in arr:\n",
    "            if n !=0 and counter[2*n] >=1:\n",
    "                return True\n",
    "            if n ==0 and counter[2*n] >=2:\n",
    "                return True\n",
    "        return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        numSet = set()\n",
    "\n",
    "        for v in arr:\n",
    "            if v * 2 in numSet or (v % 2 == 0 and v / 2 in numSet):\n",
    "                return True\n",
    "            numSet.add(v)\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)):\n",
    "                if i != j and arr[i] == 2 * arr[j]:\n",
    "                    return True\n",
    "                    break\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(i+1,len(arr)):\n",
    "                if arr[i] % 2 == 0 and arr[i] / 2 == arr[j] or arr[j] % 2 == 0 and arr[j] / 2 == arr[i]:\n",
    "                    return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        a_2=0.1\n",
    "        b=[]\n",
    "        for a in arr :\n",
    "            if a in b:\n",
    "                return True\n",
    "            a2=a*2\n",
    "            b+=[a2]\n",
    "            a_2=a/2\n",
    "            b+=[a_2]\n",
    "\n",
    "        return False\n",
    "        \n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for num in arr:\n",
    "            if num == 0:\n",
    "                if arr.count(0) > 1:\n",
    "                    return True\n",
    "            else:\n",
    "                if num*2 in arr:\n",
    "                    return True\n",
    "                if abs(num) % 2 == 0 and (num//2) in arr:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)):\n",
    "                if i != j and arr[i] == 2 * arr[j]:\n",
    "                    return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n - 1):\n",
    "            for j in range(i + 1, n):\n",
    "                if arr[i] == 2 * arr[j] or arr[j] == 2 * arr[i]:\n",
    "                    return True\n",
    "                pass\n",
    "            pass\n",
    "        return False\n",
    "\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        b = []\n",
    "        for i in range(len(arr)):\n",
    "            if arr[i] % 2 == 0:\n",
    "                b.append(int(arr[i] / 2))\n",
    "        n = b.count(0)\n",
    "        if n > 1:\n",
    "            return True\n",
    "        else:\n",
    "            for i in range(len(b)):\n",
    "                if b[i] in arr and b[i] != 0:\n",
    "                    return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in arr:\n",
    "            if i==0:\n",
    "                if arr.count(0)>=2:\n",
    "                    return True\n",
    "            else:\n",
    "                if 2*i in arr:\n",
    "                    return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if i != j and arr[i] * 2 == arr[j]:\n",
    "                    return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        newarr = list(map(str,arr))\n",
    "        newarr = ''.join(newarr)\n",
    "        for i in range(len(arr)):\n",
    "            if (arr[i] * 2) in arr:\n",
    "                if newarr.find(str(arr[i] * 2)) != i+1:\n",
    "                    return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def checkIfExist(self, arr: list[int]) -> bool:\n",
    "        for i, a in enumerate(arr):\n",
    "            for j, b in enumerate(arr):\n",
    "                if i != j and a * 2 == b:\n",
    "                    return True\n",
    "        return False\n",
    "\n",
    "# 作者：力扣官方题解\n",
    "# 链接：https://leetcode.cn/problems/check-if-n-and-its-double-exist/solutions/101742/jian-cha-zheng-shu-ji-qi-liang-bei-shu-shi-fou-cun/\n",
    "# 来源：力扣（LeetCode）\n",
    "# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in arr:\n",
    "            if i == 0:\n",
    "                if arr.count(0) >= 2:\n",
    "                    return True\n",
    "            elif 2*i in arr:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(i+1,len(arr)):\n",
    "                if arr[i] == 2 * arr[j] or arr[j] == 2 * arr[i]:\n",
    "                    return True\n",
    "        return False            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        hashtable = {}\n",
    "        for k, v in enumerate(arr):\n",
    "            hashtable[v] = k + 1\n",
    "        for k, v in hashtable.items():\n",
    "            if k == 0 and arr.count(0) > 1:\n",
    "                return True\n",
    "            if hashtable.get(2*k) and k:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)):\n",
    "                if arr[i] * 2 == arr[j] and i != j:\n",
    "                    return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        ln = len(arr)\n",
    "        dic = {arr[i]: i for i in range(ln)}\n",
    "        for j in range(ln):\n",
    "            if arr[j] * 2 in dic and dic[arr[j] * 2] != j:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        num_set = set()\n",
    "        for num in arr:\n",
    "            if num * 2 in num_set or num % 2 == 0 and num // 2 in num_set:\n",
    "                return True\n",
    "            num_set.add(num)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        d = collections.Counter(arr)\n",
    "        ref = {}\n",
    "        x = 0\n",
    "        for n in arr:\n",
    "            if n != 0 and d[2*n] >=1:\n",
    "                return True\n",
    "            if n == 0 and d[2*n] >=2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        s=set()\n",
    "        for x in arr:\n",
    "            if x in s :\n",
    "                return True\n",
    "            s.add(x*2)\n",
    "            if x %2==0:\n",
    "                s.add(x//2)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        dict = {}\n",
    "        for i in arr:\n",
    "            if 2*i in dict:\n",
    "                return True\n",
    "            if i//2 in dict and i//2*2 == i:\n",
    "                return True\n",
    "            dict[i] = True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i, a in enumerate(arr):\n",
    "            for j, b in enumerate(arr):\n",
    "                if i != j and a * 2 == b:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        flag = False\n",
    "        for i,x in enumerate(arr):\n",
    "            if flag:break\n",
    "            for j, y in enumerate(arr):\n",
    "                if i != j and (x == y * 2 or y ==x * 2):\n",
    "                    flag = True\n",
    "                    break\n",
    "        return flag"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)):\n",
    "                if arr[j] == 2 * arr[i] and i != j:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        #思路：从arr里面挨个取数，乘2，看看是否在arr里面就好了\n",
    "        n = len(arr)\n",
    "        for i in range(n - 1):\n",
    "            for j in range(i + 1, n):\n",
    "                if arr[i] == 2 * arr[j] or arr[i] * 2 == arr[j]:\n",
    "                    return True\n",
    "        \n",
    "        return False\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        c=Counter(arr)\n",
    "        for i in arr:\n",
    "            if i!=0 and i*2 in c:\n",
    "                return True\n",
    "            elif i==0 and c[i]>1:\n",
    "                return True\n",
    "        return False\n",
    "            \n",
    "            \n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        hash_T = {}\n",
    "        for num in arr:\n",
    "            if 2*num in hash_T or num/2 in hash_T:\n",
    "                return True\n",
    "            else:\n",
    "                hash_T[num] = False\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n-1):\n",
    "            for j in range(i+1,n):\n",
    "                if arr[i]*2==arr[j] or arr[j]*2==arr[i]:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def checkIfExist(self, arr: list[int]) -> bool:\n",
    "        arr.sort()\n",
    "        q = 0\n",
    "        for p in range(len(arr)):\n",
    "            while q < len(arr) and arr[p] * 2 > arr[q]:\n",
    "                q += 1\n",
    "            if q != len(arr) and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        q = len(arr) - 1\n",
    "        for p in range(len(arr)-1, -1, -1):\n",
    "            while q > -1 and arr[p] * 2 < arr[q]:\n",
    "                q -= 1\n",
    "            if q != -1 and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        return False\n",
    "\n",
    "# 作者：力扣官方题解\n",
    "# 链接：https://leetcode.cn/problems/check-if-n-and-its-double-exist/solutions/101742/jian-cha-zheng-shu-ji-qi-liang-bei-shu-shi-fou-cun/\n",
    "# 来源：力扣（LeetCode）\n",
    "# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        q = 0\n",
    "        for p in range(len(arr)):\n",
    "            while q < len(arr) and arr[p] * 2 > arr[q]:\n",
    "                q += 1\n",
    "            if q != len(arr) and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        q = len(arr) - 1\n",
    "        for p in range(len(arr) - 1, -1, -1):\n",
    "            while q > -1 and arr[p] * 2 < arr[q]:\n",
    "                q -= 1\n",
    "            if q != -1 and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        ans = set()\n",
    "        for x in arr:\n",
    "            if x * 2 in ans or x / 2 in ans:\n",
    "                return True\n",
    "            ans.add(x)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def checkIfExist(self, arr: List[int]) -> bool:\n",
    "#         dic=set()\n",
    "#         for a in arr:\n",
    "#             if a*2 in dic:\n",
    "#                 return True\n",
    "#             if a%2==0 and a//2 in dic:\n",
    "#                 return True\n",
    "#             dic.add(a)\n",
    "#         return False\n",
    "\n",
    "# ### 官：双指针--分正负数（推荐）\n",
    "# class Solution:\n",
    "#     def checkIfExist(self,arr):\n",
    "#         n=len(arr)\n",
    "#         arr.sort()### \n",
    "#         j=0 ### 正数系列\n",
    "#         for i in range(n):\n",
    "#             while j<n and arr[i]*2>arr[j]:\n",
    "#                 j+=1\n",
    "#             if j<n and i!=j and arr[i]*2==arr[j]:\n",
    "#                 return True\n",
    "#         i=0 ### 负数系列\n",
    "#         for j in range(n-1,-1,-1):\n",
    "#             while i>-1 and arr[j]*2<arr[i]:\n",
    "#                 i-=1\n",
    "#             if i>-1 and i!=j and arr[j]*2==arr[i]:\n",
    "#                 return True \n",
    "#         return False\n",
    "\n",
    "### 官2：排序+双指针（原码）\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        q = 0\n",
    "        for p in range(len(arr)):\n",
    "            while q < len(arr) and arr[p] * 2 > arr[q]:\n",
    "                q += 1\n",
    "            if q != len(arr) and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        q = len(arr) - 1\n",
    "        for p in range(len(arr) - 1, -1, -1):\n",
    "            while q > -1 and arr[p] * 2 < arr[q]:\n",
    "                q -= 1\n",
    "            if q != -1 and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        s = set ()\n",
    "        for i in arr:\n",
    "            if i * 2 in s or i % 2 == 0 and i//2 in s :\n",
    "                return True \n",
    "            s.add(i)\n",
    "        return False\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i,a in enumerate(arr):\n",
    "            for j,b in enumerate(arr):\n",
    "                if i!=j and a==2*b:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        s = set(arr)\n",
    "        if arr.count(0) > 1:\n",
    "            return True\n",
    "        return any(i and i << 1 in s for i in arr)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        q = 0\n",
    "        for p in range(len(arr)):\n",
    "            while q < len(arr) and arr[p] *2 > arr[q]:\n",
    "                q +=1\n",
    "            if q !=len(arr) and p!=q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "\n",
    "        q = len(arr) -1\n",
    "        for p in range(len(arr)-1,-1,-1):\n",
    "            while q > -1 and arr[p] * 2 < arr[q]:\n",
    "                q -=1\n",
    "            if q !=-1 and p !=q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        q = 0\n",
    "        for p in range(len(arr)):\n",
    "            while q < len(arr) and arr[p] * 2 > arr[q]:\n",
    "                q += 1\n",
    "            if q != len(arr) and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        q = len(arr) - 1\n",
    "        for p in range(len(arr) - 1, -1, -1):\n",
    "            while q > -1 and arr[p] * 2 < arr[q]:\n",
    "                q -= 1\n",
    "            if q != -1 and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        counter = collections.Counter(arr)\n",
    "        for a in arr:\n",
    "            if a != 0 and counter[a*2] >= 1:\n",
    "                return True\n",
    "            if a == 0 and counter[0] >= 2:\n",
    "                return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        s = set()\n",
    "        for x in arr:\n",
    "            if x in s: return True\n",
    "            s.add(x * 2)\n",
    "            if x % 2 == 0:\n",
    "                s.add(x//2)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        pre = set()\n",
    "        for num in arr:\n",
    "            if num % 2 == 0 and num // 2 in pre:\n",
    "                return True\n",
    "            if num * 2 in pre:\n",
    "                return True\n",
    "            pre.add(num)\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)):\n",
    "                if i == j:\n",
    "                    continue\n",
    "                if 0 == arr[i] and arr[j] == 0:\n",
    "                    return True\n",
    "                if arr[j] == 0:\n",
    "                    continue\n",
    "                \n",
    "                if arr[i] / arr[j] == 2:\n",
    "                    return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        if arr.count(0)>=2:\n",
    "            return True\n",
    "        for i in arr:\n",
    "            if 2*i in arr and i!=0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        if len(arr)<2:\n",
    "            return False\n",
    "        for i in arr:\n",
    "            if i == 0:\n",
    "                arr.remove(0)\n",
    "            if 2*i in arr:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len (arr)\n",
    "        s = set ()\n",
    "        for x in arr:\n",
    "            if 2 * x in s:\n",
    "                return True\n",
    "            if x % 2 == 0 and x // 2 in s:\n",
    "                return True\n",
    "            s.add(x)\n",
    "\n",
    "        return False    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i, a in enumerate(arr):\n",
    "            for j, b in enumerate(arr):\n",
    "                if i != j and a == 2 * b:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: list[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for a in arr:\n",
    "            if a == 0:\n",
    "                if arr.count(0) >=2:\n",
    "                    return True\n",
    "            elif a < 0:\n",
    "                if 0.5 * a > arr[-1]:\n",
    "                    return False\n",
    "                elif 0.5 * a in arr:\n",
    "                    return True\n",
    "            else:\n",
    "                if 2 * a > arr[-1]:\n",
    "                    return False\n",
    "                elif 2 * a in arr:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        s = set()\n",
    "        for x in arr:\n",
    "            if 2*x in s:\n",
    "                return True\n",
    "            if x % 2 == 0 and x // 2 in s:            \n",
    "                return True\n",
    "            s.add(x)\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        pre=set()\n",
    "        for num in arr:\n",
    "            if num%2==0 and num//2 in pre:\n",
    "                return True\n",
    "            if num*2 in pre:\n",
    "                return True\n",
    "            pre.add(num)\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        \n",
    "        def midSearch(num, arr):\n",
    "            left , right = 0, len(arr)\n",
    "\n",
    "            while left < right:\n",
    "                mid = left + (right - left) // 2\n",
    "                if arr[mid] < num:\n",
    "                    left = mid + 1\n",
    "                elif arr[mid] > num:\n",
    "                    right = mid\n",
    "                else:\n",
    "                    return True\n",
    "        arr.sort()\n",
    "        count = 0\n",
    "        for i in arr:\n",
    "            if i == 0:\n",
    "                count += 1\n",
    "        if count > 1:\n",
    "            return True\n",
    "        for i in arr:\n",
    "            if midSearch(i * 2, arr) and i != 0:\n",
    "                return True\n",
    "        return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n - 1):\n",
    "            for j in range(i + 1, n):\n",
    "                if arr[i] == 2 * arr[j] or arr[i] * 2 == arr[j]:\n",
    "                    return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        c = Counter(arr)\n",
    "        if 0 in c:\n",
    "            if c[0] >= 2:\n",
    "                return True\n",
    "            del c[0]\n",
    "        for key in c:\n",
    "            if key * 2 in c:\n",
    "                return True\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        counter=dict()\n",
    "        for i in range(len(arr)):\n",
    "            counter[arr[i]]=counter.get(arr[i],0)+1\n",
    "        for key in counter:\n",
    "            if 2*key in counter and key!=0:\n",
    "                return True\n",
    "            if key%2==0 and key//2 in counter and key!=0:\n",
    "                return True\n",
    "        if 0 in counter:\n",
    "            if counter[0]>=2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        cnt = Counter(arr)\n",
    "        for n in arr:\n",
    "            if n==0 and cnt[0]>=2:\n",
    "                return True\n",
    "            if n!=0 and cnt[2*n]>=1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        q = 0\n",
    "        for p in range(len(arr)):\n",
    "            while q < len(arr) and arr[p] * 2 > arr[q]:\n",
    "                q += 1\n",
    "            if q != len(arr) and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        q = len(arr) - 1\n",
    "        for p in range(len(arr) - 1, -1, -1):\n",
    "            while q > -1 and arr[p] * 2 < arr[q]:\n",
    "                q -= 1\n",
    "            if q != -1 and p != q and arr[p] * 2 == arr[q]:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        b = []\n",
    "        for i in range(len(arr)):\n",
    "            if arr[i] % 2 == 0:\n",
    "                b.append(int(arr[i] / 2))\n",
    "        arr.sort(reverse = False)\n",
    "        b.sort(reverse = True)\n",
    "        n = b.count(0)\n",
    "        if n > 1:\n",
    "            return True\n",
    "        else:\n",
    "            for i in range(len(b)):\n",
    "                if b[i] in arr and b[i] != 0:\n",
    "                    return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if i != j and arr[i] == arr[j] * 2:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(0, len(arr)-1):\n",
    "            if arr[i] >= 0:\n",
    "                for j in arr[i+1:]:\n",
    "                    if arr[i]*2 == j:\n",
    "                        return True\n",
    "            else:\n",
    "                for j in arr[:i]:\n",
    "                    if arr[i]*2 == j:\n",
    "                        return True\n",
    "        return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i,a in enumerate(arr):\n",
    "            for j,b in enumerate(arr):\n",
    "                if i!=j and a*2==b:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        # # numset = set(arr)\n",
    "        # cnt = Counter(arr)\n",
    "        # # print(cnt)\n",
    "        # if cnt[0] > 1:\n",
    "        #     return True\n",
    "\n",
    "        # for j in range(len(arr)):\n",
    "        #     if arr[j] * 2 in cnt and arr[j] != 0:\n",
    "        #         # print(arr[j])\n",
    "        #         return True\n",
    "        # return False\n",
    "\n",
    "        counter = Counter(arr)\n",
    "        for num in arr:\n",
    "            if num == 0 and counter[num * 2] >= 2:\n",
    "                return True\n",
    "            if num != 0 and counter[num * 2] >= 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        res=False\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(i+1,len(arr)):\n",
    "                if arr[i]==2*arr[j] or arr[j]==2*arr[i]:\n",
    "                    res=True\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i, l in enumerate(arr):\n",
    "            for j, r in enumerate(arr):\n",
    "                if i != j and (l == 2 * r or r == 2 * l):\n",
    "                    return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        if 0 in arr:\n",
    "            arr.remove(0)\n",
    "            if 0 in arr:\n",
    "                return True\n",
    "        dic = {}\n",
    "        for i in arr:\n",
    "            dic[i] = 0\n",
    "        for i in arr:\n",
    "            if dic.get(i*2,None) is not None and i != 0:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        for i, a in enumerate(arr):\n",
    "            for j, b in enumerate(arr):\n",
    "                if i != j and a * 2 == b:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        def check(arr):\n",
    "            l, r, n = 0, 1, len(arr)\n",
    "            if n < 2:\n",
    "                return False\n",
    "            if arr[0] < 0:\n",
    "                arr = [-x for x in arr[::-1]]\n",
    "            print(arr)\n",
    "            while r < n:\n",
    "                print(l, r)\n",
    "                a, b = arr[l], arr[r]\n",
    "                if 2*a==b:\n",
    "                    return True\n",
    "                if 2*a<b: l+=1\n",
    "                else: r+=1\n",
    "            return False\n",
    "\n",
    "        arr, n = sorted(arr), len(arr)\n",
    "        bound = 0\n",
    "        while bound<n and arr[bound] < 0:\n",
    "            bound += 1\n",
    "        return check(arr[:bound]) or check(arr[bound:])\n",
    "        \n",
    "    \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        hash = {}\n",
    "        for a in arr:\n",
    "            if 2 * a in hash or a / 2 in hash:\n",
    "                return True\n",
    "            else:\n",
    "                hash[a] = a\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        counter = collections.Counter(arr)\n",
    "        for n in arr:\n",
    "            if n != 0 and counter[2 * n] >= 1:\n",
    "                return True\n",
    "            if n == 0 and counter[2 * n] >= 2:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        if 0 in arr:\n",
    "            arr.remove(0)\n",
    "            if 0 in arr:\n",
    "                return True\n",
    "        uni_arr = list(set(arr))\n",
    "        for i in uni_arr:\n",
    "            if 2*i in uni_arr:\n",
    "                return True\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        # numset = set(arr)\n",
    "        cnt = Counter(arr)\n",
    "        # print(cnt)\n",
    "        if cnt[0] > 1:\n",
    "            return True\n",
    "\n",
    "        for j in range(len(arr)):\n",
    "            if arr[j] * 2 in cnt and arr[j] != 0:\n",
    "                # print(arr[j])\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkIfExist(self, arr: List[int]) -> bool:\n",
    "        d = {}\n",
    "        for i, x in enumerate(arr):\n",
    "            if x == 0 and x in d:\n",
    "                return True\n",
    "            else: d[x] = i\n",
    "        for x in arr:\n",
    "            x2 = x * 2\n",
    "            if x2 in d and x != 0: return True\n",
    "        return False\n",
    "        "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
